package com.briup.shopadmin.dao;

import com.briup.shopadmin.common.bean.Shop;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface IShopDao extends JpaRepository<Shop,Long> {

    @Query(nativeQuery = true,value = "select c2.name,count(c2.name) num\n" +
            "from  t_category c1 right join t_shop s on s.category_id=c1.id right join  t_category c2 on c1.parent_id =c2.id\n" +
            "where c2.parent_id is null\n" +
            "group by c2.name")
    List<String[]> countByCategory();

    Page<Shop> findByNameContaining(String name, PageRequest pageRequest);




}
